//
// Created by wujehy on 2020/7/8.
//

#ifndef GEEJOAN_MYSQL_EXCEPTION_H
#define GEEJOAN_MYSQL_EXCEPTION_H


#include <stdexcept>

struct MYSQL;

namespace GeeJoan
{
    namespace MySQL
    {
        class Exception : public std::runtime_error
        {
        public:

            Exception(const char *aErrorMessage, int ret);

            Exception(const std::string &aErrorMessage, int ret) :
                    Exception( aErrorMessage.c_str(), ret )
            {
            }

            Exception(MYSQL *hander, int ret);

            explicit Exception(MYSQL *hander);

            explicit Exception(const std::string &aErrorMessage) :
                    Exception( aErrorMessage.c_str(), -1 ) // 0 would be SQLITE_OK, which doesn't make sense
            {
            }

            const char *getErrorStr() const noexcept;

            int getExtendedErrorCode() const noexcept
            {
                return mExtendedErrcode;
            }

            int getErrorCode() const noexcept
            {
                return mErrcode;
            }


        private:
            int mErrcode;         ///< Error code value
            int mExtendedErrcode; ///< Detailed error code if any
            MYSQL *current_hander = nullptr;
        };
    }
}


#endif //GEEJOAN_MYSQL_EXCEPTION_H
